package yz;

import java.util.HashMap;
import java.util.Map;

/**
 *  两数之和
 *
 * @Author yangz
 * @Date 2022/9/5 23:28
 */
public class LeetCode01_TwoSum {

    public int[] twoSum(int[] numbers, int target) {
        int [] res = new int[2];
        if(numbers==null||numbers.length<2){
            return res;
        }
        Map<Integer,Integer> map = new HashMap<>();
        for(int i = 0; i < numbers.length; i++){
            if(!map.containsKey(target-numbers[i])){
                map.put(numbers[i],i);
            }else{
                res[0]= map.get(target-numbers[i]);
                res[1]= i;
                break;
            }
        }
        return res;
    }
}
